package com.hqsj;

import com.hqsj.service.BeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class WeixinApplication {

	public static void main(String[] args) {

//		//获取context
		ApplicationContext ctx = SpringApplication.run(WeixinApplication.class, args);
//
//		//获取beanFactory
//		DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) ctx.getAutowireCapableBeanFactory();
//
//		//创建bean信息
//		BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(BeanService.class);
//		beanDefinitionBuilder.addPropertyValue("name", "张三");
//
//		//动态注册bean
//		defaultListableBeanFactory.registerBeanDefinition("beanService", beanDefinitionBuilder.getBeanDefinition());

//		BeanDefinitionBuilder beanDefinitionBuilder2 = BeanDefinitionBuilder.genericBeanDefinition(BeanService.class);
//		beanDefinitionBuilder2.addPropertyValue("name", "李四");
//		defaultListableBeanFactory.registerBeanDefinition("beanService2", beanDefinitionBuilder.getBeanDefinition());

		//获取动态注册的bean
//		BeanService beanService = (BeanService) ctx.getBean("beanService");
//		beanService.print();

		//删除bean
//		defaultListableBeanFactory.removeBeanDefinition("beanService");

		//获取动态注册的bean
//		BeanService beanService2 = (BeanService) ctx.getBean("beanService");
//		beanService2.print();

	}
}
